import { request } from "@yaf/request";
import { EnumRouter } from "@/constants";
// import { toApi } from "@/service";
import type { RespCommonDataType } from "./apiType";

export * from "./apiType";

const { get } = request;

/**
 * 获取全局配置
 */
// export const getGlobalConfig = () => get<RespCommonDataType.IGlobalConfig>(toApi("api/v1/globalConfig"), {}, { isShowErrorPrompt: false }).then(resp => {
export const getGlobalConfig = () => get<RespCommonDataType.IGlobalConfig>(EnumRouter.to("config/globalConfig.json"), {}, { isShowErrorPrompt: false }).then(resp => {
  // 1. 为公共状态列表添加颜色
  const { commonStatusList, commonStatus } = resp.data;
  resp.data.commonStatusList = commonStatusList.map(item => {
    switch (item.value) {
      case commonStatus.normal:
        item.color = "green";
        return item
      case commonStatus.stop:
        item.color = "red"
        return item;
      default:
        return item
    }
  });

  return resp;
})
